From f65aeebf64381ca0c92a851acbf6f8c4b773ae2d Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 24 Jul 2014 21:16:20 +1000 Subject: [PATCH] Improve the error message for missing packages. --- src/cargo/core/resolver.rs | 8 +++++++- tests/test_cargo_compile.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/resolver.rs b/src/cargo/core/resolver.rs index c693754cf..e5a6dfab1 100644 --- a/src/cargo/core/resolver.rs +++ b/src/cargo/core/resolver.rs @@ -78,7 +78,13 @@ fn resolve_deps<'a, R: Registry>(parent: &PackageId, let pkgs = try!(ctx.registry.query(dep)); if pkgs.is_empty() { - return Err(human(format!("No package named {} found", dep))); + return Err(human(format!("No package named `{:s}` found (required by `{:s}`).\n\ + Location searched: {}\n\ + Version required: {}", + dep.get_name(), + parent.get_name(), + dep.get_namespace(), + dep.get_version_req()))); } if pkgs.len() > 1 { diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 318776140..49e45b96f 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -485,6 +485,37 @@ test!(cargo_compile_with_nested_deps_longhand { execs().with_stdout("test passed\n")); }) +// Check that Cargo gives a sensible error if a dependency can't be found +// because of a name mismatch. +test!(cargo_compile_with_dep_name_mismatch { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + + name = "foo" + version = "0.0.1" + authors = ["wycats@example.com"] + + [[bin]] + + name = "foo" + + [dependencies.notquitebar] + + path = "bar" + "#) + .file("src/foo.rs", main_file(r#""i am foo""#, ["bar"]).as_slice()) + .file("bar/Cargo.toml", basic_bin_manifest("bar").as_slice()) + .file("bar/src/bar.rs", main_file(r#""i am bar""#, []).as_slice()); + + assert_that(p.cargo_process("cargo-build"), + execs().with_status(101).with_stderr(format!( +r#"No package named `notquitebar` found (required by `foo`). +Location searched: file:{proj_dir} +Version required: * +"#, proj_dir = p.root().display()))); +}) + // test!(compiling_project_with_invalid_manifest) test!(custom_build { -- 2.30.2